package com.wu.dms.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wu.dms.dao.entity.DmsSongRecord;
import com.wu.dms.dao.sqlProvide.StatisticSqlProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.SelectProvider;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Cousin
 * @date 2024/12/28
 * @Description
 */
@Repository
public interface DmsSongRecordMapper extends BaseMapper<DmsSongRecord> {
    @Insert("INSERT INTO music.dms_song_record (song_id, date,play_cnts,valid_play_cnts) " +
            "VALUES (#{songId}, #{time},1,#{valid}) " +
            "ON DUPLICATE KEY UPDATE play_cnts = play_cnts + 1, valid_play_cnts = valid_play_cnts + #{valid}")
    void updateCount(@Param("songId") Long songId,@Param("valid")Integer valid,@Param("time") String time);

    @SelectProvider(type = StatisticSqlProvider.class, method = "selectPlayStatisWithPagination")
    List<Map<String,Object>> selectPlayStatistic(Integer pageNum, Integer pageSize, String searchWord, String beginTime, String endTime);

    @SelectProvider(type = StatisticSqlProvider.class, method = "countPlayStatisWithPagination")
    Long countPlayStatistic( String searchWord, String beginTime, String endTime);
}

